package com.cheyunkeji.er.adapter.auction;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.bean.auction.AuctionProjectBean;
import com.cheyunkeji.er.utils.ImageLoadUtil;
import com.cheyunkeji.er.utils.TimeUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/2/24 14:40.
 */

public class AuctionRecordAdapter extends MyBaseAdapter {


    private int state = 0 ;

    public AuctionRecordAdapter(ArrayList<AuctionProjectBean> dataList, Context context) {
        super(dataList, context);
    }

    public AuctionRecordAdapter(ArrayList<AuctionProjectBean> dataList, Context context, int state) {
        super(dataList, context);
        this.state = state ;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_auction_record_lv_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        AuctionProjectBean itemBean = (AuctionProjectBean) dataList.get(position);

        if (!TextUtils.isEmpty(itemBean.getCover()))
            ImageLoadUtil.loadImg(context, itemBean.getCover(), holder.ivBaojiaItem);

        holder.tvCarBrand.setText(itemBean.getTitle());
        holder.tvDesc.setText(itemBean.getIntro());


        switch (state) {

            case Constants.AUCTION_TYPE_GOT_MYSELF :
                holder.tv01.setText("得标价格：");
                holder.tv02.setText(String.valueOf(itemBean.getWinner_callprice()) + "元");
                holder.tv03.setText("得标时间：");
                holder.tv04.setText(TimeUtils.millis2String(Long.valueOf(itemBean.getEtime()) * 1000));
                break;

            case Constants.AUCTION_TYPE_LOST :

                holder.tv01.setText("我最高报价：");
                holder.tv02.setText(String.valueOf(itemBean.getCallprice()) + "元");
                holder.tv03.setText("底            价：");
                holder.tv04.setText(String.valueOf(itemBean.getWinner_callprice()) + "元");
                break;

            case Constants.AUCTION_TYPE_GOT_OTHERS :

                holder.tv01.setText("我最高报价：");
                holder.tv02.setText(String.valueOf(itemBean.getCallprice()) + "元");
                holder.tv03.setText("得标人报价：");
                holder.tv04.setText(String.valueOf(itemBean.getWinner_callprice()) + "元");
                break;

            default:
                break;
        }

        return convertView;
    }


    static class ViewHolder {

        @BindView(R.id.iv_baojia_item)
        ImageView ivBaojiaItem;
        @BindView(R.id.iv_tag)
        ImageView ivTag;
        @BindView(R.id.tv_car_brand)
        TextView tvCarBrand;
        @BindView(R.id.tv_desc)
        TextView tvDesc;
        @BindView(R.id.tv_01)
        TextView tv01;
        @BindView(R.id.tv_02)
        TextView tv02;
        @BindView(R.id.tv_03)
        TextView tv03;
        @BindView(R.id.tv_04)
        TextView tv04;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

    }
}
